/* eslint-disable */
import table2excel from 'js-table2excel'

export function export_json_to_excel({titles, columns, data, filename} = {}) {
	let index = 0
	let columnItems = []
	columns.forEach(field => {
		if (typeof (field) === 'object') {
			if (field.type === 'image') {
				field.width = field.width ? field.width : 80
				field.height = field.height ? field.height : 80
			}
			field.title = field.title ? field.title : titles[index]
			columnItems.push(field)
		} else {
			columnItems.push({ key: field, type: 'text', title: titles[index] })
		}
		index++
	});

	table2excel(columnItems, data, filename)
}
